Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adapter_to() method for moving & converting adapter weights #699

Merged
merged 1 commit into from
May 11, 2024

Conversation

calpt
Copy link
Member

@calpt calpt commented May 10, 2024

This PR:

  • introduces new methods adapter_to() & adapter_fusion_to() to move only adapter weights to device or convert dtype
  • avoids moving full model in AdapterTrainer when loading best model.

Fixes #694.

Copy link
Contributor

@TimoImhof TimoImhof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TimoImhof TimoImhof merged commit ed9a537 into adapter-hub:main May 11, 2024
3 checks passed
@calpt calpt deleted the dev/adapter_to branch May 11, 2024 08:41
@weiiiii0622
Copy link

Hello, i am running with the following code:

model = AutoAdapterModel.from_pretrained(f"{cache_dir}/Llama-2-7b-chat-hf/",cache_dir="checkpoints/hf_model")
model.half()
model.to("cuda")
model.set_active_adapters(None)
current_adapter = model.load_adapter(f"{adapter_dir}/baseline_adapter", config="scaled_parallel", set_active=True, load_as=f"baseline_adapter")
model.set_active_adapters(current_adapter)
# Move adapter to cuda
model.adapter_to(name=current_adapter, device="cuda:0", dtype=torch.float16)

and got the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[9], [line 47](vscode-notebook-cell:?execution_count=9&line=47)
     [44](vscode-notebook-cell:?execution_count=9&line=44) model_llama2.set_active_adapters(current_adapter)
     [46](vscode-notebook-cell:?execution_count=9&line=46) # Move adapter to cuda
---> [47](vscode-notebook-cell:?execution_count=9&line=47) model_llama2.adapter_to(name=current_adapter, device="cuda:0", dtype=torch.float16)
     [49](vscode-notebook-cell:?execution_count=9&line=49) # Check summary
     [50](vscode-notebook-cell:?execution_count=9&line=50) summary = model_llama2.adapter_summary()

File ~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1614, in Module.__getattr__(self, name)
   [1612](https://vscode-remote+ssh-002dremote-002btwcc.vscode-resource.vscode-cdn.net/home/b10902138/2024.07/check-adapter-training/~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1612)     if name in modules:
   [1613](https://vscode-remote+ssh-002dremote-002btwcc.vscode-resource.vscode-cdn.net/home/b10902138/2024.07/check-adapter-training/~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1613)         return modules[name]
-> [1614](https://vscode-remote+ssh-002dremote-002btwcc.vscode-resource.vscode-cdn.net/home/b10902138/2024.07/check-adapter-training/~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1614) raise AttributeError("'{}' object has no attribute '{}'".format(
   [1615](https://vscode-remote+ssh-002dremote-002btwcc.vscode-resource.vscode-cdn.net/home/b10902138/2024.07/check-adapter-training/~/.local/lib/python3.10/site-packages/torch/nn/modules/module.py:1615)     type(self).__name__, name))

AttributeError: 'LlamaAdapterModel' object has no attribute 'adapter_to'

I believe there is something wrong for LlamaAdapterModel to not have the method adapter_to.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

".to is not supported for 4-bit or 8-bit bitsandbytes models" when i use load_best_model_at_end=True in QLoRa
3 participants